namespace Web.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class InitialCreate : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.AdminNavigations",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Action = c.String(maxLength: 50),
                        Controller = c.String(maxLength: 50),
                        ParentId = c.Int(),
                        Auth = c.String(maxLength: 100),
                        Icon = c.String(maxLength: 20),
                        Text = c.String(maxLength: 20),
                        OrderId = c.Int(nullable: false),
                        Param = c.String(maxLength: 100),
                        IsDeleted = c.Boolean(nullable: false),
                        CreateTime = c.DateTime(nullable: false),
                        Ip = c.String(maxLength: 15),
                        Timestamp = c.Binary(nullable: false, fixedLength: true, timestamp: true, storeType: "rowversion"),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.AdminNavigationAuthorizations",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        AdminNavigationId = c.Int(nullable: false),
                        AuthorizationName = c.String(maxLength: 20),
                        AuthorizationNameEn = c.String(maxLength: 20),
                        Controller = c.String(maxLength: 100),
                        Action = c.String(maxLength: 100),
                        IsDeleted = c.Boolean(nullable: false),
                        CreateTime = c.DateTime(nullable: false),
                        Ip = c.String(maxLength: 15),
                        Timestamp = c.Binary(nullable: false, fixedLength: true, timestamp: true, storeType: "rowversion"),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.AdminNavigations", t => t.AdminNavigationId, cascadeDelete: true)
                .Index(t => t.AdminNavigationId);
            
            CreateTable(
                "dbo.AdminPageButtons",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        ButtonText = c.String(maxLength: 20),
                        Css = c.String(maxLength: 20),
                        Icon = c.String(maxLength: 20),
                        Type = c.Int(nullable: false),
                        Controller = c.String(maxLength: 20),
                        Action = c.String(maxLength: 20),
                        Param = c.String(maxLength: 100),
                        Auth = c.String(maxLength: 100),
                        NavigationId = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.AdminNavigations", t => t.NavigationId, cascadeDelete: true)
                .Index(t => t.NavigationId);
            
            CreateTable(
                "dbo.AdminPageButtonAuthorizations",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        ButtonId = c.Int(nullable: false),
                        NavigationAuthorizationId = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.AdminPageButtons", t => t.ButtonId, cascadeDelete: true)
                .ForeignKey("dbo.AdminNavigationAuthorizations", t => t.NavigationAuthorizationId)
                .Index(t => t.ButtonId)
                .Index(t => t.NavigationAuthorizationId);
            
            CreateTable(
                "dbo.AdminPageAuthorizations",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        NavigationId = c.Int(nullable: false),
                        NavigationAuthorizationId = c.Int(),
                        IsDeleted = c.Boolean(nullable: false),
                        CreateTime = c.DateTime(nullable: false),
                        Ip = c.String(maxLength: 15),
                        Timestamp = c.Binary(nullable: false, fixedLength: true, timestamp: true, storeType: "rowversion"),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.AdminNavigations", t => t.NavigationId, cascadeDelete: true)
                .ForeignKey("dbo.AdminNavigationAuthorizations", t => t.NavigationAuthorizationId)
                .Index(t => t.NavigationId)
                .Index(t => t.NavigationAuthorizationId);
            
            CreateTable(
                "dbo.WebManager",
                c => new
                    {
                        Id = c.Guid(nullable: false),
                        UserName = c.String(maxLength: 20),
                        RealName = c.String(maxLength: 10),
                        Password = c.String(maxLength: 100),
                        SecurityStamp = c.String(maxLength: 100),
                        IsDeleted = c.Boolean(nullable: false),
                        CreateTime = c.DateTime(nullable: false),
                        Ip = c.String(maxLength: 15),
                        Timestamp = c.Binary(nullable: false, fixedLength: true, timestamp: true, storeType: "rowversion"),
                    })
                .PrimaryKey(t => t.Id);
            
        }
        
        public override void Down()
        {
            DropForeignKey("dbo.AdminPageAuthorizations", "NavigationAuthorizationId", "dbo.AdminNavigationAuthorizations");
            DropForeignKey("dbo.AdminPageAuthorizations", "NavigationId", "dbo.AdminNavigations");
            DropForeignKey("dbo.AdminPageButtons", "NavigationId", "dbo.AdminNavigations");
            DropForeignKey("dbo.AdminPageButtonAuthorizations", "NavigationAuthorizationId", "dbo.AdminNavigationAuthorizations");
            DropForeignKey("dbo.AdminPageButtonAuthorizations", "ButtonId", "dbo.AdminPageButtons");
            DropForeignKey("dbo.AdminNavigationAuthorizations", "AdminNavigationId", "dbo.AdminNavigations");
            DropIndex("dbo.AdminPageAuthorizations", new[] { "NavigationAuthorizationId" });
            DropIndex("dbo.AdminPageAuthorizations", new[] { "NavigationId" });
            DropIndex("dbo.AdminPageButtonAuthorizations", new[] { "NavigationAuthorizationId" });
            DropIndex("dbo.AdminPageButtonAuthorizations", new[] { "ButtonId" });
            DropIndex("dbo.AdminPageButtons", new[] { "NavigationId" });
            DropIndex("dbo.AdminNavigationAuthorizations", new[] { "AdminNavigationId" });
            DropTable("dbo.WebManager");
            DropTable("dbo.AdminPageAuthorizations");
            DropTable("dbo.AdminPageButtonAuthorizations");
            DropTable("dbo.AdminPageButtons");
            DropTable("dbo.AdminNavigationAuthorizations");
            DropTable("dbo.AdminNavigations");
        }
    }
}
